﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Week3.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class UpLoadController : ControllerBase
    {
        public UpLoadController(IWebHostEnvironment web)
        {
            Web = web;
        }

        public IWebHostEnvironment Web { get; }
        /// <summary>
        /// 上传图片
        /// </summary>
        /// <param name="file"></param>
        /// <returns></returns>
        [HttpPost]
        public IActionResult UpFile(IFormFile file) 
        {
            var id=Guid.NewGuid().ToString();
            string path=Web.WebRootPath+@"\pic\"+id+file.Name;
            using (FileStream fs = System.IO.File.Create(path)) 
            {
                file.CopyTo(fs);
                fs.Close();
            }
            return Ok("/pic/" + id + file.Name);
        }

    }
}
